home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / DEMON.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  4KB  |  178 lines

  1. /*    SCCS Id: @(#)demon.c    3.0    88/11/14
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include    "hack.h"
  6.  
  7. void
  8. dsummon(ptr)        /* summon demon */
  9.     register struct permonst *ptr;
  10. {
  11. #ifdef INFERNO
  12.     register int dtype = 0, cnt = 0;
  13.  
  14.     if(is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) {
  15.  
  16.         dtype = (!rn2(20)) ? dprince() : (!rn2(4)) ? dlord() : ndemon();
  17.         cnt = (!rn2(4) && !is_dprince(&mons[dtype])) ? 2 : 1;
  18.  
  19.     } else if(is_dlord(ptr)) {
  20.  
  21.         dtype = (!rn2(50)) ? dprince() : (!rn2(20)) ? dlord() : ndemon();
  22.         cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
  23.  
  24.     } else if(is_ndemon(ptr)) {
  25.  
  26.         dtype = (!rn2(20)) ? dlord() : (!rn2(6)) ? ndemon() : monsndx(ptr);
  27.         cnt = 1;
  28.     }
  29.  
  30.     if(!dtype) return;
  31.  
  32.     while(cnt > 0) {
  33.  
  34.         (void)makemon(&mons[dtype], u.ux, u.uy);
  35.         cnt--;
  36.     }
  37. #else
  38.     (void)makemon(&mons[PM_DEMON], u.ux, u.uy);
  39. #endif
  40.     return;
  41. }
  42.  
  43. #ifdef INFERNO
  44. #define    Athome    (Inhell && !mtmp->cham)
  45.  
  46. int
  47. demon_talk(mtmp)        /* returns 1 if it won't attack. */
  48. register struct monst *mtmp;
  49. {
  50.     long    demand, offer;
  51.  
  52. #ifdef NAMED_ITEMS
  53.     if(uwep && is_artifact(uwep) && !strcmp(ONAME(uwep), "Excalibur")) {
  54.  
  55.         pline("%s looks very angry.", Xmonnam(mtmp));
  56.         return mtmp->mpeaceful = mtmp->mtame = 0;
  57.     }
  58. #endif /* NAMED_ITEMS */
  59.  
  60.     /* Slight advantage given. */
  61.     if(is_dprince(mtmp->data) && mtmp->minvis) {
  62.         mtmp->minvis = 0;
  63.         if (!Blind) pline("%s appears before you.", Xmonnam(mtmp));
  64.         pmon(mtmp);
  65.     }
  66.     if(u.usym == S_DEMON) {    /* Won't blackmail their own. */
  67.  
  68.         pline("%s says, \"Good hunting, %s.\" and vanishes.",
  69.           Xmonnam(mtmp), flags.female ? "Sister" : "Brother");
  70.         rloc(mtmp);
  71.         return(1);
  72.     }
  73.     demand = (u.ugold * (rnd(80) + 20 * Athome)) / 100;
  74.     if(!demand)          /* you have no gold */
  75.         return mtmp->mpeaceful = 0;
  76.     else {
  77.  
  78.         pline("%s demands %ld zorkmid%s for safe passage.",
  79.           Xmonnam(mtmp), demand, plur(demand));
  80.  
  81.         if((offer = bribe(mtmp)) >= demand) {
  82.         pline("%s vanishes, laughing about cowardly mortals.",
  83.               Xmonnam(mtmp));
  84.         } else {
  85.         if((long)rnd(40) > (demand - offer)) {
  86.             pline("%s scowls at you menacingly, then vanishes.",
  87.               Xmonnam(mtmp));
  88.         } else {
  89.             pline("%s gets angry...", Xmonnam(mtmp));
  90.             return mtmp->mpeaceful = 0;
  91.         }
  92.         }
  93.     }
  94.     mongone(mtmp);
  95.     return(1);
  96. }
  97. #endif
  98.  
  99. #if defined(INFERNO) || (defined(ALTARS) && defined(THEOLOGY))
  100. long
  101. bribe(mtmp)
  102. struct monst *mtmp;
  103. {
  104.     char buf[80];
  105.     long offer;
  106.  
  107.     pline("How much will you offer? ");
  108.     getlin(buf);
  109.     (void) sscanf(buf, "%ld", &offer);
  110.  
  111. /*Michael Paddon -- fix for negative offer to monster*/    /*JAR880815 - */
  112.      if(offer < 0L) {
  113.          You("try to shortchange %s, but fumble.", 
  114.              x_monnam(mtmp, 0));
  115.          offer = 0L;
  116.      } else if(offer == 0L) {
  117.         You("refuse.");
  118.      } else if(offer >= u.ugold) {
  119.         You("give %s all your gold.", x_monnam(mtmp, 0));
  120.         offer = u.ugold;
  121.     } else You("give %s %ld zorkmid%s.", x_monnam(mtmp, 0), offer,
  122.            plur(offer));
  123.  
  124.     u.ugold -= offer;
  125.     mtmp->mgold += offer;
  126.     flags.botl = 1;
  127.     return(offer);
  128. }
  129. #endif
  130.  
  131. int
  132. dprince() {
  133. #ifdef INFERNO
  134.     int    tryct, pm;
  135.  
  136.     for(tryct = 0; tryct < 20; tryct++) {
  137.         pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS);
  138.         if(!(mons[pm].geno & G_GENOD))
  139.         return(pm);
  140.     }
  141.     return(dlord());    /* approximate */
  142. #else
  143.     return(PM_DEMON);
  144. #endif
  145. }
  146.  
  147. int
  148. dlord() {
  149. #ifdef INFERNO
  150.     int    tryct, pm;
  151.  
  152.     for(tryct = 0; tryct < 20; tryct++) {
  153.         pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX);
  154.         if(!(mons[pm].geno & G_GENOD))
  155.         return(pm);
  156.     }
  157.     return(ndemon());    /* approximate */
  158. #else
  159.     return(PM_DEMON);
  160. #endif
  161. }
  162.  
  163. int
  164. ndemon() {
  165. #ifdef INFERNO
  166.     int    tryct;
  167.     struct    permonst *ptr;
  168.  
  169.     for(tryct = 0; tryct < 20; tryct++)
  170.         if(is_ndemon((ptr = mkclass(S_DEMON))))
  171.         return(monsndx(ptr));
  172.  
  173.     return(0);
  174. #else
  175.     return(PM_DEMON);
  176. #endif
  177. }
  178.